//
//  HttpAPI.m
//  Inforcollection
//  Created by macbook on 15/12/9.
//  Copyright © 2015年 oceansoft.liw. All rights reserved.
//

#import "HttpAPI.h"
#import "UIView+Toast.h"
//#define KBaseUrl @"http://172.17.150.97:8080/"

@implementation HttpAPI


+ (instancetype)shareHttpAPI
{
    static HttpAPI *_shareHttpAPI = nil;
    
    static dispatch_once_t onceToken;
    
    dispatch_once(&onceToken,^
    {
        _shareHttpAPI=[[HttpAPI alloc]init];
    });
    return _shareHttpAPI;
}

/*
 获取验证码
 */
- (void)getYZMWithDic:(NSDictionary *)info CallBack:(HttpCallBack)callback
{
    
    AFHTTPRequestOperationManager *manager  = [AFHTTPRequestOperationManager manager];
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html", @"text/json", @"application/json", nil];
    NSLog(@"%@",[BaseUrl stringByAppendingString:[APIAdress getYZM]]);
    
    [manager POST:[BaseUrl stringByAppendingString:[APIAdress getYZM]] parameters:info success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        callback(responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        callback(nil);

    }];
}




/*登录接口
 *info 是传进来的参数
 */

-(void)loginWithDict:(NSDictionary*)info CallBack:(HttpCallBack)callBack
{
    AFHTTPRequestOperationManager *manager  = [AFHTTPRequestOperationManager manager];
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html", @"text/json", @"application/json", nil];
    
    [manager POST:[BaseUrl stringByAppendingString:[APIAdress login]] parameters:info success:^(AFHTTPRequestOperation *operation, id responseObject) {
//     测试专用
        callBack(responseObject);
        

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        callBack(nil);
    }];

}

/*寄件管理的接口
 *info 是传进来的字典
 **/
- (void)sendmanagement:(NSDictionary*)info CallBack:(HttpCallBack)callback
{
    
    AFHTTPRequestOperationManager *manager  = [AFHTTPRequestOperationManager manager];

    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html", @"text/json", @"application/json", nil];

    [manager POST:[BaseUrl stringByAppendingString:[APIAdress managementAds]] parameters:info constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        
    } success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];

}
/*公告管理列表
 *info 是传进来的字典
 **/
- (void)getAnnouncementData:(NSDictionary*)Info CallBack:(HttpCallBack)callback
{
    AFHTTPRequestOperationManager *manager  = [AFHTTPRequestOperationManager manager];
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html", @"text/json", @"application/json", nil];
    
    [manager POST:[BaseUrl stringByAppendingString:[APIAdress getannouncementList]] parameters:Info constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
    
    } success:^(AFHTTPRequestOperation *operation, id responseObject) {
           callback(responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        callback(nil);
    }];

}
/*公告管理详情
 *info 是传进来的字典
 **/
- (void)getAnnouncementDateDetailsInfo:(NSDictionary*)info CallBack:(HttpCallBack)callback{
    AFHTTPRequestOperationManager *manager  = [AFHTTPRequestOperationManager manager];
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html", @"text/json", @"application/json", nil];
    NSLog(@"%@",[BaseUrl stringByAppendingString:[APIAdress getAnnouncementdetails]]);
                 
    [manager POST:[BaseUrl stringByAppendingString:[APIAdress getAnnouncementdetails]] parameters:info success:^(AFHTTPRequestOperation *operation, id responseObject) {
          callback(responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        callback(nil);

    }];


}

/*公告管理详情里面的签收
 *info 是传进来的字典
 **/

- (void)getAnnouncementSignafterreceiving:(NSDictionary*)info CallBack:(HttpCallBack)callback{
    
    AFHTTPRequestOperationManager *manager  = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html", @"text/json", @"application/json", nil];
    [manager POST:[BaseUrl stringByAppendingString:[APIAdress getAnnouncementsigne]] parameters:info constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        
    } success:^(AFHTTPRequestOperation *operation, id responseObject) {
        callback(responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        [MBProgressHUD showHUDAddedTo:SharedApplication.keyWindow text:@"网络错误" duration:1.5 whileExecutingBlock:nil];
    }];


}
/*info         这个是传进来的字典参数
 **callback    这个是提交表单返回的信息
 ***说明:       当callback的返回饿值是空的时候证明返回失败
 */
-(void)getCheckUploadStaticForServers:(NSDictionary*)info CallBack:(HttpCallBack)callback{
    AFHTTPRequestOperationManager *manager  = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html",@"text/plain", nil];
    [manager POST:[BaseUrl stringByAppendingString:[APIAdress checkUploadDataMode]]  parameters:info success:^(AFHTTPRequestOperation *operation, id responseObject) {
        callback(responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        callback(nil);
    }];


}
-(void)getDiduploadSenderList:(NSDictionary*)info CallBack:(HttpCallBack)callback{
    AFHTTPRequestOperationManager *manager  = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html",@"text/plain", nil];
    [manager POST:[BaseUrl stringByAppendingString:[APIAdress getdidUploadData]]  parameters:info success:^(AFHTTPRequestOperation *operation, id responseObject) {
        callback(responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        callback(nil);
    }];

}


@end
